package src.cn.hquanheng.java_base.javafx;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class TestLabel extends Application {

	@Override
	public void start(Stage primaryStage) throws Exception {
		// Label label = new Label("�ϲ�");
		//
		// Image image = new Image(getClass().getResourceAsStream("QQ.png"));
		// ImageView iv = new ImageView(image);
		//
		//
		// label.setFont(Font.font("Microsoft YaHei",24));
		// label.setGraphic(iv);
		// label.setTextFill(Color.BLUE);

		Scene scene = new Scene(creatUi());

		primaryStage.setScene(scene);
		primaryStage.show();

	}

	private Parent creatUi() {
//		Button button = new Button("���");
//		
//		Image image = new Image(getClass().getResourceAsStream("newFile.png"));
//		ImageView iv = new ImageView(image);
//		
//		button.setGraphic(iv);
//		
//		
//		
//		button.setOnAction((event)->{
//			System.out.println("���");
//		});
		HBox hbox = new HBox();
		hbox.setSpacing(10);
		
		Label label  = new Label("�꼶");
		hbox.getChildren().add(label);
		
		RadioButton rb1 = new RadioButton("��һ");
		RadioButton rb2 = new RadioButton("���");
		RadioButton rb3 = new RadioButton("����");
		RadioButton rb4 = new RadioButton("����");
		
		ToggleGroup tg = new ToggleGroup();
		rb1.setToggleGroup(tg);
		rb2.setToggleGroup(tg);
		rb3.setToggleGroup(tg);
		rb4.setToggleGroup(tg);
		
		rb1.setUserData(1);
		rb2.setUserData(2);
		rb3.setUserData(3);
		rb4.setUserData(4);
		
		Button button = new Button("��ѯ");
		button.setOnAction((e)->{
			Toggle toggle = tg.getSelectedToggle();
			
			if(toggle != null) {
				System.out.println(toggle.getUserData());
			}
		});
		
		//��ô����rb�л����¼�
		//���԰󶨣�javafx�������е��¼�������ƣ�mvvm
		
		//��togglegroup �����Ա仯���һ��������
		
		tg.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
			@Override
			public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
				if(newValue!=null) {
					System.out.println(newValue.getUserData());
				}
			}
			
		});
		
		hbox.getChildren().addAll(rb1,rb2,rb3,rb4);
		hbox.getChildren().add(button);
		
		return hbox;
	}

	public static void main(String[] args) {
		launch(args);
	}

}
